package collection;

import java.util.ArrayList;
import java.util.List;

/**
 * List集合提供了一对重载的add，remove方法
 */
public class ListDemo2 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println(list);//[one, two, three, four, five]
        list.add(2,"six");//void add(int index,E e)  将给定元素插入到指定位置
        System.out.println(list);//[one, two, six, three, four, five]

        String str = list.remove(3);//E remove(int index)  删除并返回指定位置对应的元素，也可以不接收
        System.out.println(list);//[one, two, six, four, five]
        System.out.println(str);//three
    }
}
